home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / FLI106C.ZIP;1 / WINSTATE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  9.6 KB  |  429 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.06c
  4. // Copyright (C) 1990, 1991, 1992
  5. // Software Dimensions
  6. //
  7. // ShiftManager --> FusionWindow
  8. //
  9.  
  10. #include "fliwin.h"
  11. #include "colors.h"
  12.  
  13. #ifdef __BCPLUSPLUS__
  14. #pragma hdrstop
  15. #endif
  16.  
  17. #include <string.h>
  18. #include <bios.h>
  19. #include <alloc.h>
  20. #include <mem.h>
  21.  
  22. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  23. //
  24. // FLICMP() -> statically/locally used by ShiftManager
  25. //
  26. // Compares two far strings -- returns 1 if alike or 0 if not alike
  27. //
  28. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  29.  
  30. static int FLICMP(char far *chka,char far *chkb,int size)
  31. {
  32.   do
  33.   {
  34.     if (*chka++!=*chkb++)
  35.       return 0;
  36.   }
  37.   while (--size);
  38.   return 1;
  39. }
  40.  
  41. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  42. //
  43. // FLICPY() -> statically/locally used by ShiftManager
  44. //
  45. // Copies one string into another
  46. //
  47. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  48.  
  49. static void FLICPY(char far *from,char far *to,int size)
  50. {
  51.   do *to++=*from++; while (--size);
  52. }
  53.  
  54. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  55. //
  56. // ShiftManager()
  57. //
  58. // Constructor
  59. //
  60. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  61.  
  62. int ShiftManager::LastShift=500;
  63. int ShiftManager::KeyLast=500;
  64.  
  65. ShiftManager::ShiftManager()
  66. {
  67.   LastShift=500;
  68.   KeyLast=500;
  69.  
  70.   Keys=0;
  71.   Alt=0;
  72.   Ctrl=0;
  73.   Normal=0;
  74.  
  75.   NumAltKeys=0;
  76.   NumCtrlKeys=0;
  77.   NumNormKeys=0;
  78.   NumKeyTies=0;
  79.  
  80.   Item=0;
  81.   PromptWidth=0;
  82.   XOffset=0;
  83.   OnLastShift=500;
  84.  
  85.   SnapShot=0;
  86.   InAWindow=0;
  87. }
  88.  
  89. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  90. //
  91. // ~ShiftManager()
  92. //
  93. // Destructor
  94. //
  95. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  96.  
  97. ShiftManager::~ShiftManager()
  98. {
  99.   if (NumAltKeys)
  100.     free(Alt);
  101.  
  102.   if (NumCtrlKeys)
  103.     free(Ctrl);
  104.  
  105.   if (NumNormKeys)
  106.     free(Normal);
  107.  
  108.   if (NumKeyTies)
  109.     free(Keys);
  110.  
  111.   if (SnapShot)
  112.     delete SnapShot;
  113. }
  114.  
  115. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  116. //
  117. // RefreshPromptLine()
  118. //
  119. // Refreshes the prompt line after a shift state change
  120. //
  121. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  122.  
  123. int ShiftManager::RefreshPromptLine()
  124. {
  125.   int BoldHelp=Colors.PromptLineBold;
  126.   int Help=Colors.PromptLineNormal;
  127.  
  128.   BlazeClass Blaze;
  129.  
  130.   MouseLocate();
  131.  
  132.   if (((bioskey(2)&8 && !NumAltKeys) ||
  133.     (bioskey(2)&4 && !NumCtrlKeys) ||
  134.     !NumNormKeys) && InAWindow)
  135.     return 0;
  136.  
  137.   if (bioskey(2)!=LastShift || (SnapShot && !FLICMP(
  138.       ((char far *)Blaze.WhatOutput()+((Blaze.WhatWidth()*2)*(Blaze.WhatHeight()-1))),
  139.       SnapShot,30) && MouseVertical!=Blaze.WhatHeight()-1))
  140.   {
  141.     LastShift=bioskey(2);
  142.  
  143.     if ((SnapShot && FLICMP(
  144.       ((char far *)Blaze.WhatOutput()+((Blaze.WhatWidth()*2)*(Blaze.WhatHeight()-1))),
  145.       SnapShot,30)) || !SnapShot)
  146.     {
  147.       if (bioskey(2)&8 && KeyLast==1) // Alt
  148.         return 1;
  149.       else if (bioskey(2)&4 && KeyLast==2) // Ctrl
  150.         return 1;
  151.       else if (!bioskey(2)&8 && !bioskey(2)&4 && !KeyLast) // Non Shifted
  152.         return 1;
  153.     }
  154.  
  155.     int NumOptions;
  156.     _PromptLine *Keyer;
  157.  
  158.     if (bioskey(2)&8)
  159.     {
  160.       KeyLast=1;
  161.       NumOptions=NumAltKeys;
  162.       Keyer=Alt;
  163.     }
  164.     else if (bioskey(2)&4)
  165.     {
  166.       KeyLast=2;
  167.       NumOptions=NumCtrlKeys;
  168.       Keyer=Ctrl;
  169.     }
  170.     else
  171.     {
  172.       KeyLast=0;
  173.       NumOptions=NumNormKeys;
  174.       Keyer=Normal;
  175.     }
  176.  
  177.     MouseHide();
  178.  
  179.     Blaze.CharacterRepeater(0,Blaze.WhatHeight()-1,Blaze.WhatWidth(),Help,0);
  180.     Blaze (1,Blaze.WhatHeight()-1);
  181.     !Blaze;
  182.     +Blaze;
  183.  
  184.     if (!NumOptions)
  185.     {
  186.       MouseShow();
  187.       return 0;
  188.     }
  189.  
  190.     Item=0;
  191.     OnLastShift=0;
  192.  
  193.     for (register int i=0,Width=0;i<NumOptions;i++)
  194.     {
  195.       if ((Keyer+i)->Key && (Keyer+i)->Info &&
  196.         *(Keyer+i)->Key && *(Keyer+i)->Info)
  197.       {
  198.         Width+=(strlen((Keyer+i)->Key)+strlen((Keyer+i)->Info)+1);
  199.         if (Width>=Blaze.WhatWidth()-1)
  200.           break;
  201.         Blaze << BoldHelp
  202.           << (Keyer+i)->Key
  203.           << ' '
  204.           << Help
  205.           << (Keyer+i)->Info;
  206.  
  207.         Width++;
  208.         if (Width>=Blaze.WhatWidth()-1)
  209.           break;
  210.         Blaze << ' ';
  211.       }
  212.     }
  213.  
  214.     if (!SnapShot)
  215.       SnapShot=new char[32];
  216.  
  217.     FLICPY(((char far *)Blaze.WhatOutput()+
  218.         ((Blaze.WhatWidth()*2)*(Blaze.WhatHeight()-1))),
  219.       SnapShot,30);
  220.  
  221.     MouseShow();
  222.   }
  223.  
  224.   return 1;
  225. }
  226.  
  227. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  228. //
  229. // CheckPromptLine()
  230. //
  231. // See if mouse is touching the prompt line
  232. //
  233. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  234.  
  235. int ShiftManager::CheckPromptLine()
  236. {
  237.   if (LastShift==500 ||
  238.      (KeyLast==1 && !NumAltKeys) ||
  239.      (KeyLast==2 && !NumCtrlKeys) ||
  240.      (KeyLast==0 && !NumNormKeys))
  241.     return 0;
  242.  
  243.   if (!bioskey(2)&8 && KeyLast==1)
  244.     return 0;
  245.   else if (!bioskey(2)&4 && KeyLast==2)
  246.     return 0;
  247.   else if ((bioskey(2)&8 || bioskey(2)&4) && !KeyLast)
  248.     return 0;
  249.  
  250.   BlazeClass Blaze;
  251.  
  252.   if (MouseEvent&MouseMoved)
  253.   {
  254.     if (OnLastShift==KeyLast)
  255.     {
  256.       MouseHide();
  257.       Blaze.ChangeBackground(XOffset,Blaze.WhatHeight()-1,PromptWidth,1,Colors.PromptLineNormal);
  258.       MouseShow();
  259.     }
  260.  
  261.     if (MouseVertical<Blaze.WhatHeight()-1)
  262.     {
  263.       Item=0;
  264.       return 1;
  265.     }
  266.  
  267.     int NumOptions;
  268.     _PromptLine *Keyer;
  269.  
  270.     if (KeyLast==1)
  271.     {
  272.       NumOptions=NumAltKeys;
  273.       Keyer=Alt;
  274.     }
  275.     else if (KeyLast==2)
  276.     {
  277.       NumOptions=NumCtrlKeys;
  278.       Keyer=Ctrl;
  279.     }
  280.     else
  281.     {
  282.       NumOptions=NumNormKeys;
  283.       Keyer=Normal;
  284.     }
  285.  
  286.     for (register int i=0,Width=0,SaveWidth=0;i<NumOptions;i++)
  287.     {
  288.       if ((Keyer+i)->Key && (Keyer+i)->Info &&
  289.         *(Keyer+i)->Key && *(Keyer+i)->Info)
  290.       {
  291.         SaveWidth=Width;
  292.         Width+=(strlen((Keyer+i)->Key)+strlen((Keyer+i)->Info)+1);
  293.         if (Width>=Blaze.WhatWidth()-1)
  294.           break;
  295.         if (MouseHorizontal>=SaveWidth && MouseHorizontal<=Width+1)
  296.         {
  297.           XOffset=SaveWidth;
  298.           PromptWidth=Width-SaveWidth+2;
  299.           Item=i+1;
  300.           MouseHide();
  301.           Blaze.ChangeBackground(XOffset,Blaze.WhatHeight()-1,PromptWidth,1,Colors.MenuHiLite);
  302.           MouseShow();
  303.           OnLastShift=KeyLast;
  304.           return 1;
  305.         }
  306.         Width++;
  307.         if (Width>=Blaze.WhatWidth()-1)
  308.           break;
  309.       }
  310.     }
  311.  
  312.     OnLastShift=KeyLast;
  313.     XOffset=0;
  314.     Width=0;
  315.     Item=0;
  316.   }
  317.   else if (MouseEvent&MouseLeftButtonRelease)
  318.   {
  319.     if (OnLastShift==KeyLast && Item && MouseVertical==Blaze.WhatHeight()-1)
  320.     {
  321.       _PromptLine *Keyer;
  322.  
  323.       if (KeyLast==1)
  324.         Keyer=Alt;
  325.       else if (KeyLast==2)
  326.         Keyer=Ctrl;
  327.       else
  328.         Keyer=Normal;
  329.       return (InAWindow)?
  330.         (Keyer+Item-1)->Event:EventHandler((Keyer+Item-1)->Event);
  331.     }
  332.   }
  333.  
  334.   return 1;
  335. }
  336.  
  337. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  338. //
  339. // DefineKey()
  340. //
  341. // Places a key and event onto the global keyboard event queue
  342. //
  343. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  344.  
  345. void ShiftManager::DefineKey(int HotKey,int Event)
  346. {
  347.   if (HotKey && Event)
  348.   {
  349.     Keys=(_HotKeys*)realloc(Keys,++NumKeyTies*sizeof(_HotKeys));
  350.     (Keys+NumKeyTies-1)->Tie=HotKey;
  351.     (Keys+NumKeyTies-1)->Event=Event;
  352.   }
  353. }
  354.  
  355. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  356. //
  357. // DefineAltKey()
  358. //
  359. // Defines an ALT key combination
  360. //
  361. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  362.  
  363. void ShiftManager::DefineAltKey(char *Key,char *Description,int Event,
  364.   int HotKey)
  365. {
  366.   Alt=(_PromptLine*)realloc(Alt,++NumAltKeys*sizeof(_PromptLine));
  367.   (Alt+NumAltKeys-1)->Key=Key;
  368.   (Alt+NumAltKeys-1)->Info=Description;
  369.   (Alt+NumAltKeys-1)->Event=Event;
  370.   DefineKey(HotKey,Event);
  371. }
  372.  
  373. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  374. //
  375. // DefineCtrlKey()
  376. //
  377. // Defines an CTRL key combination
  378. //
  379. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  380.  
  381. void ShiftManager::DefineCtrlKey(char *Key,char *Description,int Event,
  382.   int HotKey)
  383. {
  384.   Ctrl=(_PromptLine*)realloc(Ctrl,++NumCtrlKeys*sizeof(_PromptLine));
  385.   (Ctrl+NumCtrlKeys-1)->Key=Key;
  386.   (Ctrl+NumCtrlKeys-1)->Info=Description;
  387.   (Ctrl+NumCtrlKeys-1)->Event=Event;
  388.   DefineKey(HotKey,Event);
  389. }
  390.  
  391. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  392. //
  393. // DefineNormKey()
  394. //
  395. // Defines an normal (non-shifted) key combination
  396. //
  397. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  398.  
  399. void ShiftManager::DefineNormKey(char *Key,char *Description,int Event,
  400.   int HotKey)
  401. {
  402.   Normal=(_PromptLine*)realloc(Normal,++NumNormKeys*sizeof(_PromptLine));
  403.   (Normal+NumNormKeys-1)->Key=Key;
  404.   (Normal+NumNormKeys-1)->Info=Description;
  405.   (Normal+NumNormKeys-1)->Event=Event;
  406.   DefineKey(HotKey,Event);
  407. }
  408.  
  409. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  410. //
  411. // CheckEvent()
  412. //
  413. // Check all events and see if the passed event matches
  414. //
  415. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  416.  
  417. int ShiftManager::CheckEvent(int Event)
  418. {
  419.   if (NumKeyTies)
  420.   {
  421.     for (register int i=0;i<NumKeyTies;i++)
  422.     {
  423.       if ((Keys+i)->Tie==Event && (Keys+i)->Event)
  424.         return (Keys+i)->Event;
  425.     }
  426.   }
  427.   return 0;
  428. }
  429.